import { ref } from 'vue';

import { useLocalStorage } from '@vueuse/core';

import { toast } from '@/utils/toastHelper';

export function useMemoAdd(emit) {
  const title = ref('');
  const body = ref('');

  const memoList = useLocalStorage('memo-list', []);

  function addMemo() {
    memoList.value = [
      ...memoList.value,
      {
        id: Date.now(),
        title: title.value,
        body: body.value,
      },
    ];

    toast('成功添加');

    emit('back-memo-list');
  }

  return {
    title,
    body,
    addMemo,
  };
}
